package com.template.controller.websocket;

import com.template.controller.websocket.dto.Message;
import com.template.controller.websocket.service.WsService;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;

@RestController
@RequiredArgsConstructor
public class TestWsController {

    private final WsService wsService;

    @PostMapping("/sendMessage")
    public void sendMessage(@RequestBody Message message) {
        wsService.notifyFrontend(message.getMessageContent());
    }

    @PostMapping("/sendTo/{userId}")
    public void sendPerson(@RequestBody Message message, @PathVariable String userId) {
        wsService.sendToOther(userId, message.getMessageContent());
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Greeting implements Serializable {
        private String content;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Hello implements Serializable {
        private String name;
    }
}
